<?php
class ProductController extends Zendvn_Controller_Action
{
	public function init()
	{
		$template_path=TEMPLATE_PATH."/public/system";
		$this->loadTemplate($template_path);
		$this->view->headTitle()->append("-Sản Phẩm"); //Hien thi headTitle()-San pham tren cung cua trinh duyet web
		$this->view->controller = $this->_request->getParam('controller'); //Lay gia tri Controller hien thi tren link va luu no vao tham bien 'controller' giong nhu getParam('Id')
	}																	//Gia tri 'controller' nay duoc truyen sang header.php de xet dieu kien if(controller=='default') hien thi cac helpers
	public function indexAction() //Hien thi view theo duong dan /product/index/getCat/$id
	{							//Xu ly hien thi zendvn/helper/manuFactory()Xem cach hien thi helper nay trong file header.php
								//Helper manuFactory()== 'Cac hang laptop' Hien thi tren trinh duyet
		$id=$this->_request->getParam('getCat'); //Lay gia tri 'getCat' hien thi tren link(link nay duoc truyen vao URL link cua helper menuFactory()).
		$product= new Default_Model_Product();	//Sau do tao ra doi tuong Model_Product() va su dung function getProducCat($id) dong 16 phia duoi.
		$this->view->productCat= $product->getProducCat($id);//function getProducCat($id) De so sanh va lay gia tri $id lay duoc o dong 15 so sanh 'IdLoai' trong CSDL.Va gui thong so cua san pham vao array row chua columns cua san pham co 'IdLoai' trong table 'loaisp'.
	
	}
	public function filterAction() 	//View cua no la /product/filter/getId/$id
	{								//Action nay de loc ra san pham theo(hang san xuat,Dong CPU,toc do CPU) zendvn/helper/filter()='Tim theo phan khuc' Tren trinh duyet
									//Xu ly hien thi tu function filter() cua zendvn view helper(xem trong header.php)	
		$this->_helper->viewRenderer('index'); // View filterAction() ko can co filter.phtml ma khi Controller nay thuc thi no lay noi dung defaul/index.html va hien thi,nhung link Url tren trinh duyet thi khong $this->redirector('index')
		$id=$this->_request->getParam('getId');
		$product = new Default_Model_Filter();
		$this->view->productCat = $product->getProduct($id);
		
	}
	public function descriptAction() //Hien thi view theo duong dan /product/descript/getCat/$id
	{								//Xu ly va hien thi thong tin cu the tu 2 zendvn_view_helper la (bestSell() va newProduct())Xem hien thi 2 helper nay trong file footer.php
									//2 Helper nay hien thi tren trinh duyet o cot ben phai la('San pham ban chay nhat', 'Laptop moi ve')
		$id=$this->_request->getParam('getProduct');
		$product = new Default_Model_Product(); //$product la mot doi tuong cua class Model_Product()no co the la bat ky Product nao(bat ky row nao cua table)

		$productinfo=$product->getProduct($id)->toArray(); //$productinfo la mot doi tuong $product cu the co 'IdSP'==($id) va $productinfo la mot row dang array ma cac thanh phan cua array la cac columns cua table 'sanpham' 
		
		$views= $productinfo['luotxem']; // 'luotxem' la mot column trog table 'sanpham'
		$product->updateProduct($id,$views); //Xem chu thich function nay trong Model_Product.php
		
		$this->view->product=$productinfo; //render tham bien 'product' sang cho view descript.phtml
		
	}	
}